﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using F1010DB.ScoutMember;
using F1010DB.CustomEntity.ScoutMemberCustom;
using F1010DB.CustomEntity.Account;

namespace HDVN_F1_101.DV
{
    public partial class frmDanhSachDoanSinh : Form
    {
        private ScoutMemberServices serviceUnitList = null;
        public frmDanhSachDoanSinh()
        {
            InitializeComponent();
        }

        private void frmDanhSachDoanSinh_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            lstDanhSach.SelectedIndex = 0;
            initDefaultIList();

            // Load column
            DefineColumnWithHeaderForDSDoanSinh df = new DefineColumnWithHeaderForDSDoanSinh();
            Dictionary<string, string> listColumn = df.getAllColumns();
            int i = 0;
            string[] excludeColum = { "MA_DOAN_SINH", "HO_VA_TEN", "NGAY_SINH", "TEN_TINH_THANH" };
            foreach(string s in listColumn.Keys)
            {

                if (Array.IndexOf(excludeColum, s) == -1)
                {
                    listView1.Items.Add(s, listColumn[s], i);
                    i++;

                }
            }
           
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// Danh sach tieu chuan 
        /// </summary>
        private void initDefaultIList()
        {
            string[] arrDefaultCoulumn = { "MA_DOAN_SINH", "HO_VA_TEN", "NGAY_SINH", "TEN_TINH_THANH", "EMAIL", "DIA_CHI_THUONG_TRU", "SO_DIEN_THOAI_DD", "SO_DIEN_THOAI_NHA", "NGAY_TUYEN_HUA", "DON_VI_TUYEN_HUA", "TRUONG_NHAN_TH", "TRACH_VU_DOAN_SINH" };
            serviceUnitList = new ScoutMemberServices();

            serviceUnitList.setDataTableToGrid(grdView, arrDefaultCoulumn, F1010DB.Enums.EnumForScout.ListCate.DEFAULT_LIST, AccountInfo.unitCode, null);
        }

        /// <summary>
        /// Danh sach phu huynh
        /// </summary>
        private void initListParents()
        {
            string[] arrDefaultCoulumn = { "MA_DOAN_SINH", "HO_VA_TEN", "NGAY_SINH", "TEN_TINH_THANH", "EMAIL", "DIA_CHI_THUONG_TRU", "HO_VA_TEN_BA", "SO_DT_BA", "HO_VA_TEN_ME", "SO_DT_ME", "HO_VA_TEN_GIAM_HO","QUAN_HE_GIAM_HO","SO_DT_GIAM_HO"};
            serviceUnitList = new ScoutMemberServices();

            serviceUnitList.setDataTableToGrid(grdView, arrDefaultCoulumn,F1010DB.Enums.EnumForScout.ListCate.DEFAULT_LIST, AccountInfo.unitCode, null);
        }

        /// <summary>
        /// Danh sach doan sinh qua tuoi
        /// </summary>
        private void initListOverAge()
        {
            string[] arrDefaultCoulumn = { "MA_DOAN_SINH", "HO_VA_TEN", "NGAY_SINH", "TEN_TINH_THANH", "EMAIL", "DIA_CHI_THUONG_TRU", "SO_DIEN_THOAI_DD", "SO_DIEN_THOAI_NHA", "NGAY_TUYEN_HUA", "DON_VI_TUYEN_HUA", "TRUONG_NHAN_TH", "TRACH_VU_DOAN_SINH" };
            object[] value = { AccountInfo.maxAge };
            serviceUnitList = new ScoutMemberServices();

            serviceUnitList.setDataTableToGrid(grdView, arrDefaultCoulumn, F1010DB.Enums.EnumForScout.ListCate.OVER_AGE_LIST, AccountInfo.unitCode, value);
        }

        /// <summary>
        /// Danh sach doan sinh qua tuoi
        /// </summary>
        private void initReleaseList()
        {
            string[] arrDefaultCoulumn = { "MA_DOAN_SINH", "HO_VA_TEN", "NGAY_SINH", "TEN_TINH_THANH", "EMAIL", "DIA_CHI_THUONG_TRU", "SO_DIEN_THOAI_DD", "SO_DIEN_THOAI_NHA", "NGAY_TUYEN_HUA", "DON_VI_TUYEN_HUA", "TRUONG_NHAN_TH", "TRACH_VU_DOAN_SINH" };
            
            serviceUnitList = new ScoutMemberServices();
            serviceUnitList.setDataTableToGrid(grdView, arrDefaultCoulumn, F1010DB.Enums.EnumForScout.ListCate.RELEASE_LIST, AccountInfo.unitCode, null);
        }

        /// <summary>
        /// Tim kiem
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            SearchConditionForScoutMember searchCondition = new SearchConditionForScoutMember();

            searchCondition.maDoanSinh = txtMaDoanSinh.Text;
            searchCondition.hoVaTen = txtHoVaTen.Text;

            serviceUnitList = new ScoutMemberServices();

            serviceUnitList.filterRows(grdView, searchCondition);
        }

        /// <summary>
        /// Lay danh sach
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstDanhSach_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = lstDanhSach.SelectedIndex;

            //grdView.Rows.Clear();

            grdView.Columns.Clear();
            grdView.Refresh();

            if (index != 5)
            {
                switch (index)
                {

                    case 1:
                        initListParents();
                        break;
                    case 3:
                        initListOverAge();
                        break;
                    case 2:
                        initReleaseList();
                        break;
                    default:
                        initDefaultIList();
                        break;

                }
                //Khong cho chon
                listView1.Enabled = false;
                btnCustomColumn.Enabled = false;
            }
            else
            {
                // Hien thi danh sach can duoc chon cot
                listView1.Enabled = true;
                btnCustomColumn.Enabled = true;
            }
        }

        private void grpDanhSachCate_Enter(object sender, EventArgs e)
        {

        }

        private void btnCustomColumn_Click(object sender, EventArgs e)
        {
            List<string> listColumnnChecked = new List<string>();

            listColumnnChecked.Add("MA_DOAN_SINH");
            listColumnnChecked.Add("HO_VA_TEN");
            listColumnnChecked.Add("NGAY_SINH");
            listColumnnChecked.Add("TEN_TINH_THANH");
            foreach(ListViewItem item in listView1.Items)
            {
                if (item.Checked == true)
                {
                    listColumnnChecked.Add(item.Name);
                }
            }

            string[] arrCustomColumn = listColumnnChecked.ToArray();

            serviceUnitList = new ScoutMemberServices();
            serviceUnitList.setDataTableToGrid(grdView, arrCustomColumn, F1010DB.Enums.EnumForScout.ListCate.DEFAULT_LIST, AccountInfo.unitCode, null);
        }
    }
}
